package com.aktk.gameelements;

import com.aktk.gameelements.GamePlay.Orientation;

public class Fleet {
		Ship ships[];		// An array of Ship object
		int totalShips;		// Number of Ships in the Fleet

		// Default constructor
		public Fleet( int numShips ) {
			totalShips = numShips;
			ships = new Ship[ numShips ];
		}
		
		// Ships are initialized to null, then added by this function
		public void addShip( int row , int col , int l , Orientation o ) {
			for( int a = 0 ; a < totalShips ; ++a )
			{
				if( ships[a] == null )
				{
					ships[a] = new Ship( row , col , l , o );
					return;
				}
			}
		}
		
		// Checks if any more ship 
		public boolean fleetFull( ) {
			if( ships[totalShips - 1] == null )
			{
				return true;
			}
			return false;
		}
		
		// Returns number of ships still afloat
		public int ShipsRemaining() {
			int remainingShips = 0;
			for( int a = 0 ; a < totalShips ; ++a )
			{
				if ( !ships[a].isSunk() )
				{
					++remainingShips;
				}
			}
			return remainingShips;
		}
		
		// Receives missile at specified coordinates and returns true for hit, else miss
		public boolean inMissile( int row , int col ) {
			for( int a = 0 ; a < totalShips ; ++a )
			{
				if( ships[a].setHit( row , col ) )
				{
					return true;
				}
			}
			return false;
		}
		
		public int getFleetSize() {
			return totalShips;
		}
		
		public Ship getShip( int index ) {
			return ships[index]; 
		}

}
